//
//  AppDelegate.m
//  LOU
//
//  Created by 要帅气的生活 on 15/11/5.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "AppDelegate.h"
#import "HomeViewController.h"
#import "PropertyViewController.h"
#import "ClientViewController.h"
#import "WealthViewController.h"
#import "MineViewController.h"
#import "MFJNight.h"
#import "General.h"

#import "EaseMob.h"
#import <ShareSDK/ShareSDK.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "WXApi.h"
#import "WeiboApi.h"
#import "WeiboSDK.h"
#import "WXApi.h"
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "GuidanceViewController.h"
#import <SMS_SDK/SMSSDK.h>
@interface AppDelegate ()



@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self initShareSDK];
    [self initChat:application launchOptions:launchOptions];
    
    [SMSSDK registerApp:@"c4badbfa3178" withSecret:@"efa913b6f88a067e794f7e113396f2ee"];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    HomeViewController *home = [[HomeViewController alloc] init];
    
    //    [General initialization:home isPoint:YES];
    
    UINavigationController *homeNavi = [[UINavigationController alloc] initWithRootViewController:home];
    home.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"首页白.png"] selectedImage:[UIImage imageNamed:@"首页蓝.png"]];
    
    PropertyViewController *property = [[PropertyViewController alloc] init];
    UINavigationController *propertyNavi = [[UINavigationController alloc] initWithRootViewController:property];
    property.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"楼盘" image:[UIImage imageNamed:@"楼盘白.png"] selectedImage:[UIImage imageNamed:@"楼盘蓝.png"]];
    
    ClientViewController *client = [[ClientViewController alloc] init];
    UINavigationController *clientNavi = [[UINavigationController alloc] initWithRootViewController:client];
    client.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"客户" image:[UIImage imageNamed:@"客户白.png"] selectedImage:[UIImage imageNamed:@"客户蓝.png"]];
    
    WealthViewController *wealth = [[WealthViewController alloc] init];
    UINavigationController *wealthNavi = [[UINavigationController alloc] initWithRootViewController:wealth];
    wealth.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"财富" image:[UIImage imageNamed:@"财产白.png"] selectedImage:[UIImage imageNamed:@"财产蓝.png"]];
    
    MineViewController *mine = [[MineViewController alloc] init];
    UINavigationController *mineNavi = [[UINavigationController alloc] initWithRootViewController:mine];
    mine.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"我的白.png"] selectedImage:[UIImage imageNamed:@"我的蓝.png"]];
    //mine.tabBarItem =
    self.tab = [[UITabBarController alloc] init];
    _tab.viewControllers = @[homeNavi,propertyNavi,clientNavi,wealthNavi,mineNavi];
    /* tabBar背景颜色 */
    _tab.tabBar.barTintColor = [UIColor blackColor];
    _tab.tabBar.tintColor = [UIColor whiteColor];

    _tab.viewControllers = @[homeNavi,propertyNavi,clientNavi,wealthNavi,mineNavi];
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"dayOrNight"];
        NSLog(@"第一次启动");
        /*如果是第一次启动的话,使用`````(用户引导页面) 作为根视图*/
//        _tab.viewControllers = @[homeNavi,propertyNavi,clientNavi,wealthNavi,mineNavi];

        self.window.rootViewController = [[GuidanceViewController alloc] init];
        
    }  else{
    
    MFJNight *night = [MFJNight defaultNight];
    night.nightKey = [[NSUserDefaults standardUserDefaults] boolForKey:@"dayOrNight"];
    NSLog(@"%d",[[NSUserDefaults standardUserDefaults] boolForKey:@"dayOrNight"]);
    self.window.rootViewController = self.tab;
    /* tabBar背景颜色 */
    
    

   
    
    
    
        }

    return YES;
}
//下面是ShareSDK的代码配置
- (void)initShareSDK
{
    [ShareSDK registerApp:@"c23b281133e8"]; //字符串是你的ShareSDK的AppKey App Secret  f3c59e0b90d45fd319c38e62ae65ce14
    
    //添加QQ应用  注册网址  http://mobile.qq.com/api/
    [ShareSDK connectQQWithQZoneAppKey:@"1104762759"
                     qqApiInterfaceCls:[QQApiInterface class]
                       tencentOAuthCls:[TencentOAuth class]];
    //添加QQ空间应用  注册网址  http://connect.qq.com/intro/login/
    [ShareSDK connectQZoneWithAppKey:@"1104762759"
                           appSecret:@"aPld3r5vFW5et6s8"
                   qqApiInterfaceCls:[QQApiInterface class]
                     tencentOAuthCls:[TencentOAuth class]];
    //添加新浪微博应用 注册网址 http://open.weibo.com
    [ShareSDK connectSinaWeiboWithAppKey:@"568898243"
                               appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                             redirectUri:@"http://www.sharesdk.cn"];
    //添加微信应用 注册网址 http://open.weixin.qq.com
    [ShareSDK connectWeChatWithAppId:@"wxd2283c53f5d6b7fa"
                           wechatCls:[WXApi class]];
//    //当使用新浪微博客户端分享的时候需要按照下面的方法来初始化新浪的平台
//    [ShareSDK  connectSinaWeiboWithAppKey:@"363307405"
//                                appSecret:@"948f05c283bb02faf20c1ca568c1d4d1"
//                              redirectUri:@"http://www.sharesdk.cn"
//                              weiboSDKCls:[WeiboSDK class]];
    /*
     未获得appid
    //添加微信应用 注册网址 http://open.weixin.qq.com
    [ShareSDK connectWeChatWithAppId:@"wxad11f3dcf8a4d492"
                           wechatCls:[WXApi class]];
    //微信登陆的时候需要初始化
    [ShareSDK connectWeChatWithAppId:@"wxad11f3dcf8a4d492"
                           appSecret:@"030c4566f14fde20d246746dad573664"
                           wechatCls:[WXApi class]];
   */
    
    [ShareSDK ssoEnabled:YES];

}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [ShareSDK handleOpenURL:url wxDelegate:self];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];
}

//以下是环信聊天内容

- (void)initChat:(UIApplication *)application launchOptions:(NSDictionary *)launchOptions
{
//    [[EaseMob sharedInstance] registerSDKWithAppKey:@"wnhz#lou" apnsCertName:@"istore_dev"];
//    [[EaseMob sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
}
// App进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application {
//    [[EaseMob sharedInstance] applicationDidEnterBackground:application];
}
// App将要从后台返回
- (void)applicationWillEnterForeground:(UIApplication *)application
{
//    [[EaseMob sharedInstance] applicationWillEnterForeground:application];
}
- (void)applicationWillTerminate:(UIApplication *)application {
//    [[EaseMob sharedInstance] applicationWillTerminate:application];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}



@end
